import {createStore} from "vuex";

const store = createStore({
    state:{
        count:0
    },
    //不可以做异步
    mutations:{
        change(state,payload){
            state.count += payload
        }
    },
    //可以做异步
    actions:{
        change(context,payload){
            setTimeout(()=>{
                context.commit('change',payload)
            },2000)
        }
    },
    //计算属性
    getters:{
        doubleCount(state){
            return state.count * 2
        }
    }
})

export default store